DWORCLAS ;PICASSO/JOLLIS - ORMS CLASS SUPPORT;9/12/10;src/orms/ORMSCLAS.m
;;3.0;ORMS;9/12/10;1
;; $Id: DWORCLAS.m 4 2010-10-24 17:30:25Z jollis $

;;PDOC
;;SUMMARY Create a new ORMS class definition
;;DEFFNC
CREATE(CLASNAME,CLASDEFN)
;;ARG 1 CLASNAME The name of the class
;;ARG 2 CLASDEFN The definition of the class
;;PDOC/
 S OID=$$CREATE^DWORREC($$ROOTNODE^DWORREC(),"CLASDEFN",CLASNAME,"CLASNAME",CLASNAME)
 D APPEND^DWORREC(OID,"CLASDEFN",CLASDEFN)
 S ^DWCLAS(CLASNAME)=OID
 Q OID

;;PDOC
;;SUMMARY Return a comma-delimited list of the fields in a class
;;DEFFNC
LISTFLDS(CLASNAME,REVN,PARENT)
;;ARG 1 CLASNAME The name of the class
;;ARG 2 REVN The revision of the class, "N" for newest
;;ARG 3 PARENT The parent of this class for CLASPTRs
;;PDOC/
 N LDEL,PDEL,CLST,REVV,DEFNOID,CLASDEFN,HDRLINE,PK,FLDCNT,IDX
 N CURFLD,RECORDKEY,TYPEFLD,PRITYPE,SUBTYPE
 S LDEL="#" S PDEL=":" S CLST="" S REVV=REVN S HDRLINE=""
 S PK="" S FLDCNT=0 S IDX="" S CURFLD="" S RECORDKEY=""
 S PRITYPE="" S SUBTYPE="" S TYPEFLD=""
 S DEFNOID=$$RETRIEVE^DWORCLAS(CLASNAME)
 I REVN="N" S REVV=$$NEWEST^DWORREC(DEFNOID,"CLASDEFN")
 S CLASDEFN=$$INPUT^DWORREC(DEFNOID,"CLASDEFN",REVV)
 S HDRLINE=$P(CLASDEFN,LDEL,1)
 S PK=$P(HDRLINE,PDEL,4)
 S FLDCNT=+$L(CLASDEFN,LDEL)
 F IDX=2:1:FLDCNT D
 .S CURFLD=$P(CLASDEFN,LDEL,IDX)
 .S RECORDKEY=$P(CURFLD,PDEL,1)
 .S TYPEFLD=$P(CURFLD,PDEL,2)
 .S PRITYPE=$P(TYPEFLD,",",1)
 .S SUBTYPE=$P(TYPEFLD,",",2)
 .I PRITYPE'="CLASPTR" D
 ..I RECORDKEY'="" D
 ...S CLST=CLST_RECORDKEY_","
 .I PRITYPE="CLASPTR" D
 ..I RECORDKEY'="" D
 ...S CLST=CLST_$$LISTFLDS(SUBTYPE,REVN,PARENT)
 Q CLST
 
;;PDOC
;;SUMMARY Set the primary key of a class
;;DEFSUB
SETPK(CLASNAME,PK)
;;ARG 1 CLASNAME The name of the class
;;ARG 2 PK The name of the primary key field
;;PDOC/
 S ^DWCLAS(CLASNAME,"PK")=PK
 Q

;;PDOC
;;SUMMARY Get the primary key of a class
;;DEFFNC
GETPK(CLASNAME)
;;ARG 1 CLASNAME The name of the class
;;PDOC/
 Q $G(^DWCLAS(CLASNAME,"PK"))

;;PDOC
;;SUMMARY Retrieve a class's CLASDEFN ORMS ID by name
;;DEFFNC
RETRIEVE(CLASNAME)
;;ARG 1 CLASNAME The name of the class
;;PDOC/
 Q $G(^DWCLAS(CLASNAME))

;;PDOC
;;SUMMARY Get the revision number of the latest revision to this class
;;DEFFNC
REVISION(OID)
;;ARG 1 OID The OID of the object to check
;;PDOC/
 Q $$NEWEST^DWORREC(OID,"CLASDEFN")

;;PDOC
;;SUMMARY Update an existing ORMS class definition
;;DEFSUB
UPDATE(OID,CLASDEFN)
;;ARG 1 OID The OID of the record to update
;;ARG 2 CLASDEFN The CLASDEFN of the record to update
;;PDOC/
 D OUTPUT^DWORREC(OID,"CLASDEFN",CLASDEFN)
 Q
